import request from '@/utils/request';
import { download, toFormData, checkDownloadRes } from '@/utils/common';

/**
 * 分页查询员工质检得分情况分析
 */
export async function pageEtpOrganizationPerformances(params) {
  const res = await request.get('/etp/etpOrganizationPerformance/list', { params });
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 查询全部员工质检得分情况分析
 */
export async function listEtpOrganizationPerformances(params) {
  const res = await request.get('/etp/etpOrganizationPerformance/list', { params });
  if (res.data.code === 200) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据id查询员工质检得分情况分析
 */
export async function getEtpOrganizationPerformance(id) {
  const res = await request.get('/etp/etpOrganizationPerformance/' + id);
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 添加员工质检得分情况分析
 */
export async function addEtpOrganizationPerformance(data) {
  const res = await request.post('/etp/etpOrganizationPerformance', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 修改员工质检得分情况分析
 */
export async function updateEtpOrganizationPerformance(data) {
  const res = await request.put('/etp/etpOrganizationPerformance', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 删除员工质检得分情况分析
 */
export async function removeEtpOrganizationPerformance(id) {
  const res = await request.delete('/etp/etpOrganizationPerformance/' + id);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 批量删除员工质检得分情况分析
 */
export async function removeEtpOrganizationPerformances(ids) {
  const res = await request.delete('/etp/etpOrganizationPerformance/' + ids.join());
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 导出员工质检得分情况分析
 */
export async function exportEtpOrganizationPerformances(params) {
  const res = await request({
    url: '/etp/etpOrganizationPerformance/export',
    method: 'POST',
    data: toFormData(params),
    responseType: 'blob'
  });
  await checkDownloadRes(res);
  download(res.data, `etpOrganizationPerformance_${Date.now()}.xlsx`);
}
